﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Traceability.App.Domain.Model;

namespace Traceability.App.Application
{
    public class BaseRepository<T> : IBaseRepository<T> where T : BaseEntity
    {
        private readonly MyContext db;
        public BaseRepository(MyContext db)
        {
            this.db = db;
        }
        public int Create(T t)
        {
            db.Set<T>().Add(t);
            return db.SaveChanges();
        }

        public IQueryable<T> GetAll()
        {
            return db.Set<T>();
        }

        public T GetModel(int id)
        {
            return db.Set<T>().Find(id);
        }

        public int Update(T t)
        {
            db.Set<T>().Update(t);
            return db.SaveChanges();
        }
       
    }
}
